# -*- coding:utf-8 -*-
import backtrader as bt
import backtrader.feeds as btfeeds

import pandas as pd
import os
import datetime

class MyStrategy(bt.Strategy):
    pass

if __name__ == '__main__':
    cerebro = bt.Cerebro()
    cerebro = bt.Cerebro(stdstats=False)

    cerebro.broker.set_cash(100000.00)  # 设置初始资金金额
    init_fund = cerebro.broker.getvalue()
    print(f'初始资金:{init_fund}')

    filename = 'sz000002.csv'
    print(filename)
    data = pd.read_csv(filename, index_col="date", parse_dates=True)
    print(data)
    # 也可以如下处理日期
    # data.index=pd.to_datetime(data.date)
    # data.drop(columns=["date"],inplace=True)
    # print(data)

    load_data = bt.feeds.PandasData(dataname=data, fromdate=datetime.datetime(2020, 1, 1), todate=datetime.datetime(2020, 10, 18))
    cerebro.adddata(load_data)
    #cerebro.addstrategy(MyStrategy)

    #####################
    cerebro.run()
    end_fund = cerebro.broker.getvalue()
    print(f'期末资金:{end_fund}')
